﻿using System.Windows;
using FSquirrel.ViewModel;
using FSquirrel.Views;
using FSquirrel.Helpers;
using System.Windows.Controls.Ribbon;
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System;

namespace FSquirrel
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public readonly IList<string> allowedfiletypes = new ReadOnlyCollection<string>(new List<string> { "FSR", "FSL" });
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            InitializeComponent();
            Closing += (s, e) => ViewModelLocator.Cleanup();
        }

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.ExceptionObject.ToString());
        }

        private void Window_DragOver_1(object sender, DragEventArgs e)
        {
            bool dropEnabled = true;

            if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
                string[] filenames = e.Data.GetData(DataFormats.FileDrop, true) as string[];

                foreach (string filename in filenames)
                {
                    if (!allowedfiletypes.Contains(Path.GetExtension(filename).ToUpperInvariant()))
                    {
                        dropEnabled = false;
                        break;
                    }
                }
            }
            else
            {
                dropEnabled = false;
            }


            if (!dropEnabled)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
        }



    }
}